
use std::{process, thread};
use std::time::{Duration};

use hello::Cacher;

fn main() {
    let simulate_user_specified_value = 10 ;
    let simulate_random_number = 7;

    generate_workout (
        simulate_user_specified_value,
        simulate_random_number
    ) ;
}

// 模拟健身计划的计算过程
// fn simulate_expensive_calculation(intensity: u32) ->u32 {
//     println!("calculating slowly");
//     thread::sleep(Duration::from_secs(2));
//     intensity
// }

// 生成健身计划函数
fn generate_workout(intensity: u32, random_number:u32 ) {

    // 创建一个函数变量
    // let expensive_closure = |num| {
    //     println!("calculating slowly");
    //     thread::sleep(Duration::from_secs(2));
    //     num
    // };

    let mut expensive_closure = Cacher::new(|num| {
        println!("calculating slowly");
        thread::sleep(Duration::from_secs(2));
        num
    });


    if intensity < 25 {
        // 今天做多少个俯卧撑
        println!("Today do {} pushups! ",
            // simulate_expensive_calculation(intensity)
            expensive_closure.value(intensity)
        );
        // 今天做多少个仰卧起坐
        println!("Next do {} situps! ",
            // simulate_expensive_calculation(intensity)
            expensive_closure.value(intensity)
        );
    } else {
        if random_number == 3 {
            println!("Take a break today! Remember to stay hydrate!");
        } else {
            println!("Today, run for {} minutes! ",
                // simulate_expensive_calculation(intensity)
                expensive_closure.value(intensity)
            );
        }
    }
}

